<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><meta name="generator" content="Hexo 3.9.0"><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png"><link rel="icon" type="image/png" sizes="32x32" href="/favicon.ico"><link rel="icon" type="image/png" sizes="16x16" href="/favicon.ico"><link rel="mask-icon" href="/images/logo.svg" color="#222"><meta name="baidu-site-verification" content="WIIeufYjj6"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css"><script id="hexo-configurations">var NexT=window.NexT||{},CONFIG={hostname:new URL("http://winddoing.github.io").hostname,root:"/",scheme:"Mist",version:"7.7.0",exturl:!1,sidebar:{position:"right",width:300,display:"post",padding:18,offset:12,onmobile:!1},copycode:{enable:!0,show_result:!1,style:"flat"},back2top:{enable:!0,sidebar:!1,scrollpercent:!1},bookmark:{enable:!1,color:"#222",save:"auto"},fancybox:!1,mediumzoom:!1,lazyload:!1,pangu:!1,comments:{style:"tabs",active:"livere",storage:!0,lazyload:!1,nav:null,activeClass:"livere"},algolia:{appID:"OWFNL0AG1F",apiKey:"796a4b50e2653330cac4e0f8b1f8ade4",indexName:"winddoing",hits:{per_page:10},labels:{input_placeholder:"输入关键词",hits_empty:"没有找到与「${query}」相关的内容",hits_stats:"${hits} 条相关记录，共耗时 ${time} ms"}},localsearch:{enable:!0,trigger:"auto",top_n_per_article:1,unescape:!1,preload:!1},path:"search.xml",motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}}}</script><meta name="description" content="TGSI    Tungsten Graphics Shader Infrastructure"><meta name="keywords" content="mesa"><meta property="og:type" content="article"><meta property="og:title" content="TGSI for Mesa"><meta property="og:url" content="http://winddoing.github.io/post/58638.html"><meta property="og:site_name" content="Winddoing&#39;s Blog"><meta property="og:description" content="TGSI    Tungsten Graphics Shader Infrastructure"><meta property="og:locale" content="zh-CN"><meta property="og:image" content="http://winddoing.github.io/images/2019/09/shader_irs_2015.png"><meta property="og:image" content="http://winddoing.github.io/images/2019/09/new_shader_ir.png"><meta property="og:image" content="http://winddoing.github.io/images/2019/09/shader_tgsi.png"><meta property="og:image" content="http://winddoing.github.io/images/2019/11/glsl_build_link.png"><meta property="og:image" content="http://winddoing.github.io/images/2019/11/shader_create_flowchart.png"><meta property="og:image" content="http://winddoing.github.io/images/2019/11/virgl_shader_switch.png"><meta property="og:updated_time" content="2020-07-04T09:34:15.244Z"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="TGSI for Mesa"><meta name="twitter:description" content="TGSI    Tungsten Graphics Shader Infrastructure"><meta name="twitter:image" content="http://winddoing.github.io/images/2019/09/shader_irs_2015.png"><link rel="canonical" href="http://winddoing.github.io/post/58638.html"><script id="page-configurations">CONFIG.page={sidebar:"",isHome:!1,isPost:!0}</script><link rel="stylesheet" href="//cdn.jsdelivr.net/gh/theme-next/theme-next-needmoreshare2@1/needsharebutton.min.css"><style>#needsharebutton-postbottom{cursor:pointer;height:26px;margin-top:10px;position:relative}#needsharebutton-postbottom .btn{border:1px solid $btn-default-border-color;border-radius:3px;display:initial;padding:1px 4px}</style><title>TGSI for Mesa | Winddoing's Blog</title><script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?38fa95924670925239ef842cb0c8722b";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><noscript><style>.sidebar-inner,.use-motion .brand,.use-motion .collection-header,.use-motion .comments,.use-motion .menu-item,.use-motion .pagination,.use-motion .post-block,.use-motion .post-body,.use-motion .post-header{opacity:initial}.use-motion .site-subtitle,.use-motion .site-title{opacity:initial;top:initial}.use-motion .logo-line-before i{left:initial}.use-motion .logo-line-after i{right:initial}</style></noscript></head><body itemscope itemtype="http://schema.org/WebPage"><div class="container use-motion"><div class="headband"></div><header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-container"><div class="site-meta"><div><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">Winddoing's Blog</span><span class="logo-line-after"><i></i></span></a></div><h1 class="site-subtitle" itemprop="description">Follow Excellent, Success will Chase you</h1></div><div class="site-nav-toggle"><div class="toggle" aria-label="切换导航栏"><span class="toggle-line toggle-line-first"></span><span class="toggle-line toggle-line-middle"></span><span class="toggle-line toggle-line-last"></span></div></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-fw fa-home"></i> 首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i> 标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i> 分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i> 归档</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i> 关于</a></li><li class="menu-item menu-item-search"><a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i> 搜索</a></li></ul></nav><div class="site-search"><div class="popup search-popup"><div class="search-header"><span class="search-icon"><i class="fa fa-search"></i></span><div class="search-input-container"> <input autocomplete="off" autocorrect="off" autocapitalize="none" placeholder="搜索..." spellcheck="false" type="text" id="search-input"></div><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span></div><div id="search-result"></div></div><div class="search-pop-overlay"></div></div></div></header><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span>0%</span></div><main class="main"><div class="main-inner"><div class="content-wrap"><div class="content"><div class="posts-expand"><article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN"><link itemprop="mainEntityOfPage" href="http://winddoing.github.io/post/58638.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/images/Winddoing.jpg"><meta itemprop="name" content="Winddoing"><meta itemprop="description" content="失败缘于忽视细处，成功始于重视小事。"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Winddoing's Blog"></span><header class="post-header"><h2 class="post-title" itemprop="name headline"> TGSI for Mesa</h2><div class="post-meta"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i></span> <span class="post-meta-item-text">发表于</span> <time title="创建时间：2019-09-26 22:39:00" itemprop="dateCreated datePublished" datetime="2019-09-26T22:39:00+08:00">2019-09-26</time></span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-folder-o"></i></span> <span class="post-meta-item-text">分类于</span> <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/多媒体/" itemprop="url" rel="index"><span itemprop="name">多媒体</span></a></span> ， <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/多媒体/mesa/" itemprop="url" rel="index"><span itemprop="name">mesa</span></a></span></span><span id="/post/58638.html" class="post-meta-item leancloud_visitors" data-flag-title="TGSI for Mesa" title="阅读次数"><span class="post-meta-item-icon"><i class="fa fa-eye"></i></span> <span class="post-meta-item-text">阅读次数：</span><span class="leancloud-visitors-count"></span></span><span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i></span> <span class="post-meta-item-text">阅读次数：</span><span id="busuanzi_value_page_pv"></span></span><br><span class="post-meta-item" title="本文字数"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i></span> <span class="post-meta-item-text">本文字数：</span> <span>18k</span></span><span class="post-meta-item" title="阅读时长"><span class="post-meta-item-icon"><i class="fa fa-clock-o"></i></span> <span class="post-meta-item-text">阅读时长 &asymp;</span> <span>17 分钟</span></span></div></header><div class="post-body" itemprop="articleBody"><blockquote><p><code>TGSI</code> Tungsten Graphics Shader Infrastructure</p></blockquote><a id="more"></a><blockquote><p>In a Gallium driver, these are first transformed into TGSI by the state tracker and are then transformed into something that will run on the card by the driver.<a href="http://www.informit.com/articles/article.aspx?p=1554200&amp;seqNum=5" target="_blank" rel="noopener">^link</a></p></blockquote><blockquote><p>TGSI, Tungsten Graphics Shader Infrastructure, is an intermediate language for describing shaders. Since Gallium is inherently shaderful, shaders are an important part of the API. TGSI is the only intermediate representation used by all drivers.</p></blockquote><p><img src="/images/2019/09/shader_irs_2015.png" alt="shader_IRs_2015"><br><img src="/images/2019/09/new_shader_ir.png" alt="new_shader_ir"></p><p>TGSI是Gallium框架中的所有驱动程序使用着色器的唯一中间表示形式,这里<code>特指</code>的是<code>着色器</code>的中间形式，着色器对驱动而言的所有格式将是TGSI。</p><h2 id="TGSI中间语言"><a href="#TGSI中间语言" class="headerlink" title="TGSI中间语言"></a>TGSI中间语言</h2><p>介于在着色器（GLSL）代码与GPU指令之间的一种中间语言，类似与C语言与CPU指令之间存在的汇编语言一样。</p><p>在Mesa上，GLSL首先被编译器翻译成tgsi中间语言，然后显卡特定的驱动将这些tgsi语言的代码编译成GPU指令。</p><p><img src="/images/2019/09/shader_tgsi.png" alt="shader_gtsi"></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">glxgears: shader</span><br><span class="line">FRAG</span><br><span class="line">PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1</span><br><span class="line">DCL IN[0], COLOR, COLOR</span><br><span class="line">DCL OUT[0], COLOR</span><br><span class="line">  0: MOV OUT[0], IN[0]</span><br><span class="line">  1: END</span><br><span class="line"></span><br><span class="line">glxgears: shader</span><br><span class="line">VERT</span><br><span class="line">DCL IN[0]</span><br><span class="line">DCL OUT[0], POSITION</span><br><span class="line">DCL OUT[1], COLOR</span><br><span class="line">DCL CONST[0..10]</span><br><span class="line">DCL TEMP[0..3]</span><br><span class="line">IMM[0] FLT32 &#123;0x00000000, 0x3f800000, 0x00000000, 0x00000000&#125;</span><br><span class="line">  0: MUL TEMP[0], IN[0].xxxx, CONST[0]</span><br><span class="line">  1: MAD TEMP[0], IN[0].yyyy, CONST[1], TEMP[0]</span><br><span class="line">  2: MAD TEMP[0], IN[0].zzzz, CONST[2], TEMP[0]</span><br><span class="line">  3: MAD OUT[0], IN[0].wwww, CONST[3], TEMP[0]</span><br><span class="line">  4: DP3 TEMP[1].x, CONST[4], CONST[4]</span><br><span class="line">  5: RSQ TEMP[1].x, |TEMP[1]|</span><br><span class="line">  6: MUL TEMP[0], CONST[4], TEMP[1].xxxx</span><br><span class="line">  7: MOV TEMP[2], CONST[5]</span><br><span class="line">  8: MOV_SAT OUT[1], TEMP[2]</span><br><span class="line">  9: DP3 TEMP[3], TEMP[0], CONST[6]</span><br><span class="line"> 10: MAX TEMP[1], IMM[0].xxxy, TEMP[3]</span><br><span class="line"> 11: SLT TEMP[1].z, IMM[0].xxxx, TEMP[3]</span><br><span class="line"> 12: ADD TEMP[2], CONST[8], TEMP[2]</span><br><span class="line"> 13: MAD TEMP[2], TEMP[1].yyyy, CONST[9], TEMP[2]</span><br><span class="line"> 14: MAD_SAT OUT[1].xyz, TEMP[1].zzzz, CONST[10], TEMP[2]</span><br><span class="line"> 15: END</span><br></pre></td></tr></table></figure><blockquote><p>glxgears在渲染中生成的部分TGSI代码</p><ul><li><a href="https://freedesktop.org/wiki/Software/gallium/tgsi-specification.pdf" target="_blank" rel="noopener">TGSI specification</a></li><li><a href="https://gallium.readthedocs.io/en/latest/tgsi.html#instruction-set" target="_blank" rel="noopener">TGSI Instruction Set</a></li></ul></blockquote><ul><li><code>FRAG</code>:fragment片元着色器</li><li><code>VERT</code>:vertex顶点着色器</li><li><code>DCL</code>: declaration 申明resources</li><li><code>IMM</code>: immediate 立即数</li><li><code>PROPERTY</code> : property 性质</li></ul><h2 id="着色器的编译链接"><a href="#着色器的编译链接" class="headerlink" title="着色器的编译链接"></a>着色器的编译链接</h2><p><img src="/images/2019/11/glsl_build_link.png" alt="glsl_build_link"></p><blockquote><p>GLSL中则通过两种对象——<code>着色器对象</code>和<code>着色器程序对象</code>——来分别处理编译过程和连接过程</p></blockquote><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">call glShaderSource(shader=58, count=3, )</span><br><span class="line">string[0]=&#123;#version 140</span><br><span class="line">#extension GL_ARB_shader_bit_encoding : require</span><br><span class="line">&#125;</span><br><span class="line">string[1]=&#123;in vec4 in_0;</span><br><span class="line">in vec4 in_1;</span><br><span class="line"></span><br><span class="line">  smooth                     out  vec4 vso_g0A0_f;</span><br><span class="line">uniform float winsys_adjust_y;</span><br><span class="line">vec4 temp0[1];</span><br><span class="line">uniform uvec4 vsconst0[8];</span><br><span class="line">&#125;</span><br><span class="line">string[2]=&#123;void main(void)</span><br><span class="line">&#123;</span><br><span class="line">temp0[0] = vec4((((in_0.xxxx) * uintBitsToFloat(vsconst0[0]))));</span><br><span class="line">temp0[0] = vec4(((in_0.yyyy) * uintBitsToFloat(vsconst0[1]) +  temp0[0] ));</span><br><span class="line">temp0[0] = vec4(((in_0.zzzz) * uintBitsToFloat(vsconst0[2]) +  temp0[0] ));</span><br><span class="line">gl_Position = vec4(((in_0.wwww) * uintBitsToFloat(vsconst0[3]) +  temp0[0] ));</span><br><span class="line">temp0[0] = vec4((((in_1.xxxx) * uintBitsToFloat(vsconst0[4]))));</span><br><span class="line">temp0[0] = vec4(((in_1.yyyy) * uintBitsToFloat(vsconst0[5]) +  temp0[0] ));</span><br><span class="line">temp0[0] = vec4(((in_1.zzzz) * uintBitsToFloat(vsconst0[6]) +  temp0[0] ));</span><br><span class="line">vso_g0A0_f = vec4(((in_1.wwww) * uintBitsToFloat(vsconst0[7]) +  temp0[0] ));</span><br><span class="line">gl_Position.y = gl_Position.y * winsys_adjust_y;</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br><span class="line">call glCompileShader(58)</span><br><span class="line">call glGetShaderiv(shader=58, pname=0x8b81, params=1)</span><br><span class="line">call glCreateProgram(): 60</span><br><span class="line">call glAttachShader(program=60, shader=58)</span><br><span class="line">call glAttachShader(program=60, shader=59)</span><br><span class="line">call glBindAttribLocation(60, 0, in_0)</span><br><span class="line">call glBindAttribLocation(60, 1, in_1)</span><br><span class="line">call glLinkProgram(program=60)</span><br><span class="line">call glGetProgramiv(60, 0x8b82, 833648032)</span><br><span class="line">call glGetUniformLocation(program=60, name=winsys_adjust_y): val=0</span><br><span class="line">call glUseProgram(60)</span><br></pre></td></tr></table></figure><ul><li><code>glShaderSource</code>: 替换着色器对象中的源代码</li><li><code>glCompileShader</code>: 编译一个着色器对象</li><li><code>glGetShaderiv</code>: 从着色器对象返回一个参数</li><li><code>glCreateProgram</code>: 创建一个空program对象并返回一个可以被引用的非零值（program ID）</li><li><code>glUseProgram</code>: 安装program对象作为当前渲染状态的一部分</li></ul><p><img src="/images/2019/11/shader_create_flowchart.png" alt="shader_create_flowchart"></p><h2 id="GLSL使用"><a href="#GLSL使用" class="headerlink" title="GLSL使用"></a>GLSL使用</h2><p>着色器代码：</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">char</span> vertex_shader[] =</span><br><span class="line"><span class="string">"attribute vec3 position;\n"</span></span><br><span class="line"><span class="string">"attribute vec3 normal;\n"</span></span><br><span class="line"><span class="string">"\n"</span></span><br><span class="line"><span class="string">"uniform mat4 ModelViewProjectionMatrix;\n"</span></span><br><span class="line"><span class="string">"uniform mat4 NormalMatrix;\n"</span></span><br><span class="line"><span class="string">"uniform vec4 LightSourcePosition;\n"</span></span><br><span class="line"><span class="string">"uniform vec4 MaterialColor;\n"</span></span><br><span class="line"><span class="string">"\n"</span></span><br><span class="line"><span class="string">"varying vec4 Color;\n"</span></span><br><span class="line"><span class="string">"\n"</span></span><br><span class="line"><span class="string">"void main(void)\n"</span></span><br><span class="line"><span class="string">"&#123;\n"</span></span><br><span class="line"><span class="string">"    // Transform the normal to eye coordinates\n"</span></span><br><span class="line"><span class="string">"    vec3 N = normalize(vec3(NormalMatrix * vec4(normal, 1.0)));\n"</span></span><br><span class="line"><span class="string">"\n"</span></span><br><span class="line"><span class="string">"    // The LightSourcePosition is actually its direction for directional light\n"</span></span><br><span class="line"><span class="string">"    vec3 L = normalize(LightSourcePosition.xyz);\n"</span></span><br><span class="line"><span class="string">"\n"</span></span><br><span class="line"><span class="string">"    // Multiply the diffuse value by the vertex color (which is fixed in this case)\n"</span></span><br><span class="line"><span class="string">"    // to get the actual color that we will use to draw this vertex with\n"</span></span><br><span class="line"><span class="string">"    float diffuse = max(dot(N, L), 0.0);\n"</span></span><br><span class="line"><span class="string">"    Color = diffuse * MaterialColor;\n"</span></span><br><span class="line"><span class="string">"\n"</span></span><br><span class="line"><span class="string">"    // Transform the position to clip coordinates\n"</span></span><br><span class="line"><span class="string">"    gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0);\n"</span></span><br><span class="line"><span class="string">"&#125;"</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">char</span> fragment_shader[] =</span><br><span class="line"><span class="string">"precision mediump float;\n"</span></span><br><span class="line"><span class="string">"varying vec4 Color;\n"</span></span><br><span class="line"><span class="string">"\n"</span></span><br><span class="line"><span class="string">"void main(void)\n"</span></span><br><span class="line"><span class="string">"&#123;\n"</span></span><br><span class="line"><span class="string">"    gl_FragColor = Color;\n"</span></span><br><span class="line"><span class="string">"&#125;"</span>;</span><br></pre></td></tr></table></figure><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* Compile the vertex shader */</span></span><br><span class="line">p = vertex_shader;</span><br><span class="line">v = glCreateShader(GL_VERTEX_SHADER);</span><br><span class="line">glShaderSource(v, <span class="number">1</span>, &amp;p, <span class="literal">NULL</span>);</span><br><span class="line">glCompileShader(v);</span><br><span class="line">glGetShaderInfoLog(v, <span class="keyword">sizeof</span> msg, <span class="literal">NULL</span>, msg);</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"vertex shader info: %s\n"</span>, msg);</span><br></pre></td></tr></table></figure><p><code>glCompileShader</code>主要编译着色器的源代码（即vertex_shader中的GLSL代码）</p><ul><li>编译后的代码是TGSI中间代码？</li><li>如果是在哪个阶段进行的转换？</li><li>在virgl驱动中的着色器代码是否进行了转换？</li></ul><h3 id="glCompileShader"><a href="#glCompileShader" class="headerlink" title="glCompileShader"></a>glCompileShader</h3><blockquote><p><code>glCompileShader</code> compiles the source code strings that have been stored in the shader object specified by shader.</p></blockquote><p>在mesa中的函数调用流程：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">_mesa_CompileShader (src/mesa/main/shaderapi.c)</span><br><span class="line"> \-&gt;_mesa_compile_shader</span><br><span class="line">     \-&gt;ensure_builtin_types</span><br><span class="line">     |-&gt;_mesa_glsl_compile_shader</span><br></pre></td></tr></table></figure><blockquote><p>版本：19.3.0-devel 237c7636ca4c429d4dbfce95b6e3281a8309eac7</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Shader intermediate representation.</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * Note that if the driver requests something other than TGSI, it must</span></span><br><span class="line"><span class="comment"> * always be prepared to receive TGSI in addition to its preferred IR.</span></span><br><span class="line"><span class="comment"> * If the driver requests TGSI as its preferred IR, it will *always*</span></span><br><span class="line"><span class="comment"> * get TGSI.</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * Note that PIPE_SHADER_IR_TGSI should be zero for backwards compat with</span></span><br><span class="line"><span class="comment"> * state trackers that only understand TGSI.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">enum</span> pipe_shader_ir</span><br><span class="line">&#123;</span><br><span class="line">   PIPE_SHADER_IR_TGSI = <span class="number">0</span>,</span><br><span class="line">   PIPE_SHADER_IR_NATIVE,</span><br><span class="line">   PIPE_SHADER_IR_NIR,</span><br><span class="line">   PIPE_SHADER_IR_NIR_SERIALIZED,</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Plug in the program and shader-related device driver functions.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">void</span></span><br><span class="line">st_init_program_functions(struct dd_function_table *functions)</span><br><span class="line">&#123;</span><br><span class="line">   functions-&gt;NewProgram = st_new_program;</span><br><span class="line">   functions-&gt;DeleteProgram = st_delete_program;</span><br><span class="line">   functions-&gt;ProgramStringNotify = st_program_string_notify;</span><br><span class="line">   functions-&gt;NewATIfs = st_new_ati_fs;</span><br><span class="line">   functions-&gt;LinkShader = st_link_shader;</span><br><span class="line">   functions-&gt;SetMaxShaderCompilerThreads = st_max_shader_compiler_threads;</span><br><span class="line">   functions-&gt;GetShaderProgramCompletionStatus =</span><br><span class="line">      st_get_shader_program_completion_status;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><blockquote><p>file: src/mesa/state_tracker/st_cb_program.c</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Link a shader.</span></span><br><span class="line"><span class="comment"> * Called via ctx-&gt;Driver.LinkShader()</span></span><br><span class="line"><span class="comment"> * This is a shared function that branches off to either GLSL IR -&gt; TGSI or</span></span><br><span class="line"><span class="comment"> * GLSL IR -&gt; NIR</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">GLboolean</span><br><span class="line">st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)</span><br></pre></td></tr></table></figure><blockquote><p>file: src/mesa/state_tracker/st_glsl_to_ir.cpp</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Link a shader.</span></span><br><span class="line"><span class="comment"> * This actually involves converting GLSL IR into an intermediate TGSI-like IR</span></span><br><span class="line"><span class="comment"> * with code lowering and other optimizations.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> GLboolean</span><br><span class="line"> st_link_tgsi(struct gl_context *ctx, struct gl_shader_program *prog)</span><br></pre></td></tr></table></figure><blockquote><p>file: src/mesa/state_tracker/st_glsl_to_tgsi.cpp</p></blockquote><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">st_link_shader</span><br><span class="line">\/</span><br><span class="line">st_link_tgsi</span><br></pre></td></tr></table></figure><h2 id="virgl中着色器的转换"><a href="#virgl中着色器的转换" class="headerlink" title="virgl中着色器的转换"></a>virgl中着色器的转换</h2><p>amdgpu使用开源驱动</p><p><img src="/images/2019/11/virgl_shader_switch.png" alt="virgl_shader_switch"></p><blockquote><p>Then, 3D commands. These are close to what we can find in a API like Vulkan. We can setup a viewport, scissor state, create a VBO, and draw it. Shaders are also supported, but we first need to translate them to TGSI; an assembly-like representation. Once on the host, they will be re-translated to GLSL and sent to OpenGL.<br><a href="https://studiopixl.com/2017-08-27/3d-acceleration-using-virtio.html" target="_blank" rel="noopener">https://studiopixl.com/2017-08-27/3d-acceleration-using-virtio.html</a></p></blockquote><ul><li>在tgsi的传输中为什么不直接使用tgsi token进行传输，而要转换为text的形式传输？？？<ul><li>地址空间的不同是否相关？</li><li>tgsi text转换为tgsi token的过程中与当前使用到的纹理数据等其他资源进行关联？</li></ul></li></ul><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">tgsi_instruction</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">   <span class="keyword">unsigned</span> Type       : <span class="number">4</span>;  <span class="comment">/* TGSI_TOKEN_TYPE_INSTRUCTION */</span></span><br><span class="line">   <span class="keyword">unsigned</span> NrTokens   : <span class="number">8</span>;  <span class="comment">/* UINT */</span></span><br><span class="line">   <span class="keyword">unsigned</span> Opcode     : <span class="number">8</span>;  <span class="comment">/* TGSI_OPCODE_ */</span></span><br><span class="line">   <span class="keyword">unsigned</span> Saturate   : <span class="number">1</span>;  <span class="comment">/* BOOL */</span></span><br><span class="line">   <span class="keyword">unsigned</span> NumDstRegs : <span class="number">2</span>;  <span class="comment">/* UINT */</span></span><br><span class="line">   <span class="keyword">unsigned</span> NumSrcRegs : <span class="number">4</span>;  <span class="comment">/* UINT */</span></span><br><span class="line">   <span class="keyword">unsigned</span> Label      : <span class="number">1</span>;</span><br><span class="line">   <span class="keyword">unsigned</span> Texture    : <span class="number">1</span>;</span><br><span class="line">   <span class="keyword">unsigned</span> Memory     : <span class="number">1</span>;</span><br><span class="line">   <span class="keyword">unsigned</span> Precise    : <span class="number">1</span>;</span><br><span class="line">   <span class="keyword">unsigned</span> Padding    : <span class="number">1</span>;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">tgsi_instruction_texture</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">   <span class="keyword">unsigned</span> Texture  : <span class="number">8</span>;    <span class="comment">/* TGSI_TEXTURE_ */</span></span><br><span class="line">   <span class="keyword">unsigned</span> NumOffsets : <span class="number">4</span>;</span><br><span class="line">   <span class="keyword">unsigned</span> ReturnType : <span class="number">3</span>; <span class="comment">/* TGSI_RETURN_TYPE_x */</span></span><br><span class="line">   <span class="keyword">unsigned</span> Padding : <span class="number">17</span>;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">/*</span><br><span class="line"> * If tgsi_instruction::Label is TRUE, tgsi_instruction_label follows.</span><br><span class="line"> *</span><br><span class="line"> * If tgsi_instruction::Texture is TRUE, tgsi_instruction_texture follows.</span><br><span class="line"> *   if texture instruction has a number of offsets,</span><br><span class="line"> *   then tgsi_instruction::Texture::NumOffset of tgsi_texture_offset follow.</span><br><span class="line"> *</span><br><span class="line"> * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow.</span><br><span class="line"> *</span><br><span class="line"> * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow.</span><br><span class="line"> *</span><br><span class="line"> * tgsi_instruction::NrTokens contains the total number of words that make the</span><br><span class="line"> * instruction, including the instruction word.</span><br><span class="line"> */</span><br></pre></td></tr></table></figure><blockquote><p>tgsi_instruction_texture:表明存在指令纹理，其与纹理资源数据之间的关系？</p></blockquote><h3 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">glxgears: shader</span><br><span class="line">FRAG</span><br><span class="line">PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1</span><br><span class="line">DCL IN[0], COLOR, COLOR</span><br><span class="line">DCL OUT[0], COLOR</span><br><span class="line">  0: MOV OUT[0], IN[0]</span><br><span class="line">  1: END</span><br><span class="line"></span><br><span class="line">glxgears: GLSL:glxgears: #version 140</span><br><span class="line"></span><br><span class="line">   in  vec4 ex_c0;</span><br><span class="line">out vec4 fsout_c0;</span><br><span class="line">out vec4 fsout_c1;</span><br><span class="line">out vec4 fsout_c2;</span><br><span class="line">out vec4 fsout_c3;</span><br><span class="line">out vec4 fsout_c4;</span><br><span class="line">out vec4 fsout_c5;</span><br><span class="line">out vec4 fsout_c6;</span><br><span class="line">out vec4 fsout_c7;</span><br><span class="line">void main(void)</span><br><span class="line">&#123;</span><br><span class="line">fsout_c0 = vec4(((ex_c0)));</span><br><span class="line">fsout_c1 = fsout_c0;</span><br><span class="line">fsout_c2 = fsout_c0;</span><br><span class="line">fsout_c3 = fsout_c0;</span><br><span class="line">fsout_c4 = fsout_c0;</span><br><span class="line">fsout_c5 = fsout_c0;</span><br><span class="line">fsout_c6 = fsout_c0;</span><br><span class="line">fsout_c7 = fsout_c0;</span><br><span class="line">&#125;</span><br><span class="line">glxgears:</span><br></pre></td></tr></table></figure><blockquote><p>TGSI转换成GLSL</p></blockquote><h2 id="amdgpu中着色器的转换"><a href="#amdgpu中着色器的转换" class="headerlink" title="amdgpu中着色器的转换"></a>amdgpu中着色器的转换</h2><p>在radeonsi用户空间驱动中tgsi的使用</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Setup actions for TGSI memory opcode, including texture opcodes.</span><br></pre></td></tr></table></figure><blockquote><p>TGSI与texture之间在渲染时，之间的联系？？</p></blockquote><h3 id="radeonsi-for-shader"><a href="#radeonsi-for-shader" class="headerlink" title="radeonsi for shader"></a>radeonsi for shader</h3><p>目前LLVM是amdgpu的后端编译器，在mesa19.3中使用<code>ACO</code>（AMD COmpiler）编译着色器代码</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">TGSI-&gt;LLVM</span><br></pre></td></tr></table></figure><blockquote><p>It was just two days ago that Valve’s performance-focused “ACO” shader compiler was submitted for review to be included in Mesa for the “RADV” Radeon Vulkan driver. Just minutes ago that new shader compiler back-end was merged for Mesa 19.3.</p><p>ACO, short for the AMD COmpiler, is the effort led by Valve at creating a more performant and optimized shader compiler for the Radeon Linux graphics driver. Besides trying to generate the fastest shaders, ACO also aims to provide speedy shader compilation too, as an alternative to the AMDGPU LLVM shader compiler back-end. Initially ACO is for the RADV Vulkan driver but it may be brought to the RadeonSI OpenGL driver in the future. At the moment ACO is in good shape for Volcanic Islands through Vega while the Navi shader support is in primitive form.</p><ul><li><a href="https://www.phoronix.com/scan.php?page=news_item&amp;px=Mesa-19.3-Lands-RADV-ACO" target="_blank" rel="noopener">Valve’s ACO Shader Compiler For The Mesa Radeon Vulkan Driver Just Landed</a></li></ul></blockquote><h3 id="ISA-Code"><a href="#ISA-Code" class="headerlink" title="ISA Code"></a>ISA Code</h3><p>Instruction Set Architecture(指令集架构) —— ISA</p><blockquote><p>The AMDGPU backend provides <code>ISA code</code> generation for AMD GPUs, starting with the R600 family up until the current GCN families. It lives in the lib/Target/AMDGPU directory.</p></blockquote><blockquote><ul><li><a href="https://www.llvm.org/docs/AMDGPUUsage.html#amdgpu-intrinsics" target="_blank" rel="noopener">User Guide for AMDGPU Backend</a></li></ul></blockquote><ul><li><a href="https://rocm-documentation.readthedocs.io/en/latest/GCN_ISA_Manuals/testdocbook.html#testdocbook" target="_blank" rel="noopener">“Vega” Instruction Set Architecture</a></li><li><a href="https://rocm-documentation.readthedocs.io/en/latest/GCN_ISA_Manuals/GCN-ISA-Manuals.html" target="_blank" rel="noopener">GCN ISA Manuals</a></li></ul><h3 id="着色器形式的转换"><a href="#着色器形式的转换" class="headerlink" title="着色器形式的转换"></a>着色器形式的转换</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">+-------+     +---------+    +---------+     +------+     +------+    +-------+</span><br><span class="line">|       |     |         |    |         |     |      |     |      |    |       |</span><br><span class="line">| GLSL  +-----&gt; GLSL IR +----&gt;   NIR   +-----&gt; TGSI +-----&gt; LLVM +----&gt;  ISA  |</span><br><span class="line">|       |     |         |    |         |     |      |     |      |    |       |</span><br><span class="line">+--+----+     +---------+    +---------+     +--+---+     +------+    +----+--+</span><br><span class="line">   |                                            |                          |</span><br><span class="line">   |                                            |      radeonsi_dri.so     |</span><br><span class="line">   |                common                      |           amdgpu         |</span><br></pre></td></tr></table></figure><h2 id="示例-1"><a href="#示例-1" class="headerlink" title="示例"></a>示例</h2><h3 id="GLSL着色器"><a href="#GLSL着色器" class="headerlink" title="GLSL着色器"></a>GLSL着色器</h3><ul><li>vertex shader</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">//vertex顶点着色器</span><br><span class="line">varying vec3 lightDir, normal;</span><br><span class="line"></span><br><span class="line">void main()</span><br><span class="line">&#123;</span><br><span class="line">        lightDir = normalize(vec3(gl_LightSource[0].position));</span><br><span class="line">        normal = normalize(gl_NormalMatrix * gl_Normal);</span><br><span class="line"></span><br><span class="line">        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ul><li>fragment shader</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">//fragment片元着色器</span><br><span class="line">varying vec3 lightDir, normal;</span><br><span class="line"></span><br><span class="line">void main()</span><br><span class="line">&#123;</span><br><span class="line">        float intensity;</span><br><span class="line">        vec3 n;</span><br><span class="line">        vec4 color;</span><br><span class="line"></span><br><span class="line">        n = normalize(normal);</span><br><span class="line"></span><br><span class="line">        intensity = max(dot(lightDir,n),0.0);</span><br><span class="line">        color = vec4(1.0, 0, 1.0, 1) * intensity;</span><br><span class="line"></span><br><span class="line">        gl_FragColor = color;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h3 id="TGSI-text"><a href="#TGSI-text" class="headerlink" title="TGSI text"></a>TGSI text</h3><p>通过mesa编译后生成的TGSI token进行dump出的text</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">VIRGL_DEBUG=tgsi ./a.out</span><br></pre></td></tr></table></figure><ul><li>vertex shader</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">TGSI:</span><br><span class="line">---8&lt;---</span><br><span class="line">VERT</span><br><span class="line">DCL IN[0]</span><br><span class="line">DCL IN[1]</span><br><span class="line">DCL OUT[0], POSITION</span><br><span class="line">DCL OUT[1], GENERIC[9]</span><br><span class="line">DCL OUT[2].xy, GENERIC[10]</span><br><span class="line">DCL CONST[0..14]</span><br><span class="line">DCL TEMP[0..2], LOCAL</span><br><span class="line">  0: MUL TEMP[0].xyz, CONST[8].xyzz, IN[1].xxxx</span><br><span class="line">  1: MAD TEMP[0].xyz, CONST[9].xyzz, IN[1].yyyy, TEMP[0].xyzz</span><br><span class="line">  2: MAD TEMP[0].xyz, CONST[10].xyzz, IN[1].zzzz, TEMP[0].xyzz</span><br><span class="line">  3: DP3 TEMP[1].x, TEMP[0].xyzz, TEMP[0].xyzz</span><br><span class="line">  4: RSQ TEMP[1].x, TEMP[1].xxxx</span><br><span class="line">  5: MUL TEMP[0].xyz, TEMP[0].xyzz, TEMP[1].xxxx</span><br><span class="line">  6: MUL TEMP[1], CONST[11], IN[0].xxxx</span><br><span class="line">  7: MAD TEMP[1], CONST[12], IN[0].yyyy, TEMP[1]</span><br><span class="line">  8: MAD TEMP[1], CONST[13], IN[0].zzzz, TEMP[1]</span><br><span class="line">  9: MAD TEMP[1], CONST[14], IN[0].wwww, TEMP[1]</span><br><span class="line"> 10: DP3 TEMP[2].x, CONST[3].xyzz, CONST[3].xyzz</span><br><span class="line"> 11: RSQ TEMP[2].x, TEMP[2].xxxx</span><br><span class="line"> 12: MUL TEMP[2].xyz, CONST[3].xyzz, TEMP[2].xxxx</span><br><span class="line"> 13: MOV TEMP[2].w, TEMP[0].xxxx</span><br><span class="line"> 14: MOV OUT[2].xy, TEMP[0].yzyy</span><br><span class="line"> 15: MOV OUT[0], TEMP[1]</span><br><span class="line"> 16: MOV OUT[1], TEMP[2]</span><br><span class="line"> 17: END</span><br><span class="line"></span><br><span class="line">---8&lt;---</span><br></pre></td></tr></table></figure><ul><li>fragment shader</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">TGSI:</span><br><span class="line">---8&lt;---</span><br><span class="line">FRAG</span><br><span class="line">PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1</span><br><span class="line">DCL IN[0], GENERIC[9], PERSPECTIVE</span><br><span class="line">DCL IN[1].xy, GENERIC[10], PERSPECTIVE</span><br><span class="line">DCL OUT[0], COLOR</span><br><span class="line">DCL TEMP[0..1], LOCAL</span><br><span class="line">IMM[0] FLT32 &#123;0x3f800000, 0x00000000, 0x00000000, 0x00000000&#125;</span><br><span class="line">  0: MOV TEMP[0].x, IN[0].wwww</span><br><span class="line">  1: MOV TEMP[0].yz, IN[1].yxyy</span><br><span class="line">  2: DP3 TEMP[1].x, TEMP[0].xyzz, TEMP[0].xyzz</span><br><span class="line">  3: RSQ TEMP[1].x, TEMP[1].xxxx</span><br><span class="line">  4: MUL TEMP[0].xyz, TEMP[0].xyzz, TEMP[1].xxxx</span><br><span class="line">  5: DP3 TEMP[0].x, IN[0].xyzz, TEMP[0].xyzz</span><br><span class="line">  6: MAX TEMP[0].x, TEMP[0].xxxx, IMM[0].yyyy</span><br><span class="line">  7: MUL TEMP[0], IMM[0].xyxx, TEMP[0].xxxx</span><br><span class="line">  8: MOV OUT[0], TEMP[0]</span><br><span class="line">  9: END</span><br><span class="line"></span><br><span class="line">---8&lt;---</span><br></pre></td></tr></table></figure><h3 id="TGSI转换GLSL"><a href="#TGSI转换GLSL" class="headerlink" title="TGSI转换GLSL"></a>TGSI转换GLSL</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">VREND_DEBUG=shader virgl_test_server</span><br></pre></td></tr></table></figure><ul><li>vertex shader</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br></pre></td><td class="code"><pre><span class="line">a.out: shader</span><br><span class="line">VERT</span><br><span class="line">DCL IN[0]</span><br><span class="line">DCL IN[1]</span><br><span class="line">DCL OUT[0], POSITION</span><br><span class="line">DCL OUT[1], GENERIC[9]</span><br><span class="line">DCL OUT[2].xy, GENERIC[10]</span><br><span class="line">DCL CONST[0..14]</span><br><span class="line">DCL TEMP[0..2], LOCAL</span><br><span class="line">  0: MUL TEMP[0].xyz, CONST[8].xyzz, IN[1].xxxx</span><br><span class="line">  1: MAD TEMP[0].xyz, CONST[9].xyzz, IN[1].yyyy, TEMP[0].xyzz</span><br><span class="line">  2: MAD TEMP[0].xyz, CONST[10].xyzz, IN[1].zzzz, TEMP[0].xyzz</span><br><span class="line">  3: DP3 TEMP[1].x, TEMP[0].xyzz, TEMP[0].xyzz</span><br><span class="line">  4: RSQ TEMP[1].x, TEMP[1].xxxx</span><br><span class="line">  5: MUL TEMP[0].xyz, TEMP[0].xyzz, TEMP[1].xxxx</span><br><span class="line">  6: MUL TEMP[1], CONST[11], IN[0].xxxx</span><br><span class="line">  7: MAD TEMP[1], CONST[12], IN[0].yyyy, TEMP[1]</span><br><span class="line">  8: MAD TEMP[1], CONST[13], IN[0].zzzz, TEMP[1]</span><br><span class="line">  9: MAD TEMP[1], CONST[14], IN[0].wwww, TEMP[1]</span><br><span class="line"> 10: DP3 TEMP[2].x, CONST[3].xyzz, CONST[3].xyzz</span><br><span class="line"> 11: RSQ TEMP[2].x, TEMP[2].xxxx</span><br><span class="line"> 12: MUL TEMP[2].xyz, CONST[3].xyzz, TEMP[2].xxxx</span><br><span class="line"> 13: MOV TEMP[2].w, TEMP[0].xxxx</span><br><span class="line"> 14: MOV OUT[2].xy, TEMP[0].yzyy</span><br><span class="line"> 15: MOV OUT[0], TEMP[1]</span><br><span class="line"> 16: MOV OUT[1], TEMP[2]</span><br><span class="line"> 17: END</span><br><span class="line"></span><br><span class="line">a.out: GLSL:a.out: #version 140</span><br><span class="line">#extension GL_ARB_shader_bit_encoding : require</span><br><span class="line">in vec4 in_0;</span><br><span class="line">in vec4 in_1;</span><br><span class="line"></span><br><span class="line">                             out  vec4 vso_g9A0_f;</span><br><span class="line"></span><br><span class="line">                             out  vec4 vso_g10A0_f;</span><br><span class="line">uniform float winsys_adjust_y;</span><br><span class="line">vec4 temp0[3];</span><br><span class="line">uniform uvec4 vsconst0[15];</span><br><span class="line">void main(void)</span><br><span class="line">&#123;</span><br><span class="line">temp0[0].xyz = vec3(((uintBitsToFloat(vsconst0[8].xyzz) * (in_1.xxxx))).xyz);</span><br><span class="line">temp0[0].xyz = vec3((uintBitsToFloat(vsconst0[9].xyzz) * (in_1.yyyy) +  temp0[0].xyzz ).xyz);</span><br><span class="line">temp0[0].xyz = vec3((uintBitsToFloat(vsconst0[10].xyzz) * (in_1.zzzz) +  temp0[0].xyzz ).xyz);</span><br><span class="line">temp0[1].x = float(dot(vec3( temp0[0].xyzz ), vec3( temp0[0].xyzz )));</span><br><span class="line">temp0[1].x = float(inversesqrt( temp0[1].xxxx .x));</span><br><span class="line">temp0[0].xyz = vec3((( temp0[0].xyzz  *  temp0[1].xxxx )).xyz);</span><br><span class="line">temp0[1] = vec4(((uintBitsToFloat(vsconst0[11]) * (in_0.xxxx))));</span><br><span class="line">temp0[1] = vec4((uintBitsToFloat(vsconst0[12]) * (in_0.yyyy) +  temp0[1] ));</span><br><span class="line">temp0[1] = vec4((uintBitsToFloat(vsconst0[13]) * (in_0.zzzz) +  temp0[1] ));</span><br><span class="line">temp0[1] = vec4((uintBitsToFloat(vsconst0[14]) * (in_0.wwww) +  temp0[1] ));</span><br><span class="line">temp0[2].x = float(dot(vec3(uintBitsToFloat(vsconst0[3].xyzz)), vec3(uintBitsToFloat(vsconst0[3].xyzz))));</span><br><span class="line">temp0[2].x = float(inversesqrt( temp0[2].xxxx .x));</span><br><span class="line">temp0[2].xyz = vec3(((uintBitsToFloat(vsconst0[3].xyzz) *  temp0[2].xxxx )).xyz);</span><br><span class="line">temp0[2].w = float(( temp0[0].xxxx .w));</span><br><span class="line">vso_g10A0_f.xy = vec2(( temp0[0].yzyy .xy));</span><br><span class="line">gl_Position = vec4(( temp0[1] ));</span><br><span class="line">vso_g9A0_f = vec4(( temp0[2] ));</span><br><span class="line">gl_Position.y = gl_Position.y * winsys_adjust_y;</span><br><span class="line">&#125;</span><br><span class="line">a.out:</span><br><span class="line">a.out: GLSL:a.out: #version 140</span><br><span class="line"></span><br><span class="line">smooth    in  vec4 vso_g9A0_f;</span><br><span class="line"></span><br><span class="line">smooth    in  vec4 vso_g10A0_f;</span><br><span class="line">out vec4 fsout_c0;</span><br><span class="line">out vec4 fsout_c1;</span><br><span class="line">out vec4 fsout_c2;</span><br><span class="line">out vec4 fsout_c3;</span><br><span class="line">out vec4 fsout_c4;</span><br><span class="line">out vec4 fsout_c5;</span><br><span class="line">out vec4 fsout_c6;</span><br><span class="line">out vec4 fsout_c7;</span><br><span class="line">vec4 temp0[2];</span><br><span class="line">void main(void)</span><br><span class="line">&#123;</span><br><span class="line">temp0[0].x = float(((vso_g9A0_f.wwww).x));</span><br><span class="line">temp0[0].yz = vec2(((vso_g10A0_f.yxyy).yz));</span><br><span class="line">temp0[1].x = float(dot(vec3( temp0[0].xyzz ), vec3( temp0[0].xyzz )));</span><br><span class="line">temp0[1].x = float(inversesqrt( temp0[1].xxxx .x));</span><br><span class="line">temp0[0].xyz = vec3((( temp0[0].xyzz  *  temp0[1].xxxx )).xyz);</span><br><span class="line">temp0[0].x = float(dot(vec3((vso_g9A0_f.xyzz)), vec3( temp0[0].xyzz )));</span><br><span class="line">temp0[0].x = float((max( temp0[0].xxxx , (vec4(0,0,0,0)))).x);</span><br><span class="line">temp0[0] = vec4((((vec4(1,0,1,1)) *  temp0[0].xxxx )));</span><br><span class="line">fsout_c0 = vec4(( temp0[0] ));</span><br><span class="line">fsout_c1 = fsout_c0;</span><br><span class="line">fsout_c2 = fsout_c0;</span><br><span class="line">fsout_c3 = fsout_c0;</span><br><span class="line">fsout_c4 = fsout_c0;</span><br><span class="line">fsout_c5 = fsout_c0;</span><br><span class="line">fsout_c6 = fsout_c0;</span><br><span class="line">fsout_c7 = fsout_c0;</span><br><span class="line">&#125;</span><br><span class="line">a.out:</span><br><span class="line">a.out: GLSL:a.out: #version 140</span><br><span class="line">#extension GL_ARB_shader_bit_encoding : require</span><br><span class="line">in vec4 in_0;</span><br><span class="line">in vec4 in_1;</span><br><span class="line"></span><br><span class="line">  smooth                     out  vec4 vso_g9A0_f;</span><br><span class="line"></span><br><span class="line">  smooth                     out  vec4 vso_g10A0_f;</span><br><span class="line">uniform float winsys_adjust_y;</span><br><span class="line">vec4 temp0[3];</span><br><span class="line">uniform uvec4 vsconst0[15];</span><br><span class="line">void main(void)</span><br><span class="line">&#123;</span><br><span class="line">temp0[0].xyz = vec3(((uintBitsToFloat(vsconst0[8].xyzz) * (in_1.xxxx))).xyz);</span><br><span class="line">temp0[0].xyz = vec3((uintBitsToFloat(vsconst0[9].xyzz) * (in_1.yyyy) +  temp0[0].xyzz ).xyz);</span><br><span class="line">temp0[0].xyz = vec3((uintBitsToFloat(vsconst0[10].xyzz) * (in_1.zzzz) +  temp0[0].xyzz ).xyz);</span><br><span class="line">temp0[1].x = float(dot(vec3( temp0[0].xyzz ), vec3( temp0[0].xyzz )));</span><br><span class="line">temp0[1].x = float(inversesqrt( temp0[1].xxxx .x));</span><br><span class="line">temp0[0].xyz = vec3((( temp0[0].xyzz  *  temp0[1].xxxx )).xyz);</span><br><span class="line">temp0[1] = vec4(((uintBitsToFloat(vsconst0[11]) * (in_0.xxxx))));</span><br><span class="line">temp0[1] = vec4((uintBitsToFloat(vsconst0[12]) * (in_0.yyyy) +  temp0[1] ));</span><br><span class="line">temp0[1] = vec4((uintBitsToFloat(vsconst0[13]) * (in_0.zzzz) +  temp0[1] ));</span><br><span class="line">temp0[1] = vec4((uintBitsToFloat(vsconst0[14]) * (in_0.wwww) +  temp0[1] ));</span><br><span class="line">temp0[2].x = float(dot(vec3(uintBitsToFloat(vsconst0[3].xyzz)), vec3(uintBitsToFloat(vsconst0[3].xyzz))));</span><br><span class="line">temp0[2].x = float(inversesqrt( temp0[2].xxxx .x));</span><br><span class="line">temp0[2].xyz = vec3(((uintBitsToFloat(vsconst0[3].xyzz) *  temp0[2].xxxx )).xyz);</span><br><span class="line">temp0[2].w = float(( temp0[0].xxxx .w));</span><br><span class="line">vso_g10A0_f.xy = vec2(( temp0[0].yzyy .xy));</span><br><span class="line">gl_Position = vec4(( temp0[1] ));</span><br><span class="line">vso_g9A0_f = vec4(( temp0[2] ));</span><br><span class="line">gl_Position.y = gl_Position.y * winsys_adjust_y;</span><br><span class="line">&#125;</span><br><span class="line">a.out:</span><br></pre></td></tr></table></figure><ul><li>fragment shader</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">a.out: shader</span><br><span class="line">FRAG</span><br><span class="line">PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1</span><br><span class="line">DCL IN[0], GENERIC[9], PERSPECTIVE</span><br><span class="line">DCL IN[1].xy, GENERIC[10], PERSPECTIVE</span><br><span class="line">DCL OUT[0], COLOR</span><br><span class="line">DCL TEMP[0..1], LOCAL</span><br><span class="line">IMM[0] FLT32 &#123;0x3f800000, 0x00000000, 0x00000000, 0x00000000&#125;</span><br><span class="line">  0: MOV TEMP[0].x, IN[0].wwww</span><br><span class="line">  1: MOV TEMP[0].yz, IN[1].yxyy</span><br><span class="line">  2: DP3 TEMP[1].x, TEMP[0].xyzz, TEMP[0].xyzz</span><br><span class="line">  3: RSQ TEMP[1].x, TEMP[1].xxxx</span><br><span class="line">  4: MUL TEMP[0].xyz, TEMP[0].xyzz, TEMP[1].xxxx</span><br><span class="line">  5: DP3 TEMP[0].x, IN[0].xyzz, TEMP[0].xyzz</span><br><span class="line">  6: MAX TEMP[0].x, TEMP[0].xxxx, IMM[0].yyyy</span><br><span class="line">  7: MUL TEMP[0], IMM[0].xyxx, TEMP[0].xxxx</span><br><span class="line">  8: MOV OUT[0], TEMP[0]</span><br><span class="line">  9: END</span><br><span class="line"></span><br><span class="line">a.out: GLSL:a.out: #version 140</span><br><span class="line"></span><br><span class="line">smooth    in  vec4 vso_g9A0_f;</span><br><span class="line"></span><br><span class="line">smooth    in  vec4 vso_g10A0_f;</span><br><span class="line">out vec4 fsout_c0;</span><br><span class="line">out vec4 fsout_c1;</span><br><span class="line">out vec4 fsout_c2;</span><br><span class="line">out vec4 fsout_c3;</span><br><span class="line">out vec4 fsout_c4;</span><br><span class="line">out vec4 fsout_c5;</span><br><span class="line">out vec4 fsout_c6;</span><br><span class="line">out vec4 fsout_c7;</span><br><span class="line">vec4 temp0[2];</span><br><span class="line">void main(void)</span><br><span class="line">&#123;</span><br><span class="line">temp0[0].x = float(((vso_g9A0_f.wwww).x));</span><br><span class="line">temp0[0].yz = vec2(((vso_g10A0_f.yxyy).yz));</span><br><span class="line">temp0[1].x = float(dot(vec3( temp0[0].xyzz ), vec3( temp0[0].xyzz )));</span><br><span class="line">temp0[1].x = float(inversesqrt( temp0[1].xxxx .x));</span><br><span class="line">temp0[0].xyz = vec3((( temp0[0].xyzz  *  temp0[1].xxxx )).xyz);</span><br><span class="line">temp0[0].x = float(dot(vec3((vso_g9A0_f.xyzz)), vec3( temp0[0].xyzz )));</span><br><span class="line">temp0[0].x = float((max( temp0[0].xxxx , (vec4(0,0,0,0)))).x);</span><br><span class="line">temp0[0] = vec4((((vec4(1,0,1,1)) *  temp0[0].xxxx )));</span><br><span class="line">fsout_c0 = vec4(( temp0[0] ));</span><br><span class="line">fsout_c1 = fsout_c0;</span><br><span class="line">fsout_c2 = fsout_c0;</span><br><span class="line">fsout_c3 = fsout_c0;</span><br><span class="line">fsout_c4 = fsout_c0;</span><br><span class="line">fsout_c5 = fsout_c0;</span><br><span class="line">fsout_c6 = fsout_c0;</span><br><span class="line">fsout_c7 = fsout_c0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><ul><li>打印着色器程序相关的所有参数和字段<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ST_DEBUG=mesa ./a.out</span><br></pre></td></tr></table></figure></li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * Print all of a program&apos;s parameters/fields to stderr.</span><br><span class="line"> */</span><br><span class="line">void</span><br><span class="line">_mesa_print_program_parameters(struct gl_context *ctx, const struct gl_program *prog)</span><br><span class="line">&#123;</span><br><span class="line">   _mesa_fprint_program_parameters(stderr, ctx, prog);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><blockquote><p>file: mesa/program/prog_print.c</p></blockquote><h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ul><li><a href="https://gallium.readthedocs.io/en/latest/tgsi.html" target="_blank" rel="noopener">TGSI</a></li><li><a href="https://freedesktop.org/wiki/Software/gallium/gallium3d-xds2007.pdf" target="_blank" rel="noopener">gallium3d-xds2007</a></li><li><a href="http://ndesh26.github.io/programming/2016/07/04/A-Beginners-guide-to-TGSI/" target="_blank" rel="noopener">A beginners guide to TGSI</a></li><li><a href="http://www.informit.com/articles/article.aspx?p=1554200" target="_blank" rel="noopener">The State of Open Source 3D</a></li><li><a href="https://learnopengl.com/Getting-started/Shaders" target="_blank" rel="noopener">learnopengl–Shaders</a>|<a href="https://learnopengl-cn.github.io/#" target="_blank" rel="noopener">【CN】</a></li><li><a href="https://www.cnblogs.com/shoemaker/p/linux_graphics11.html" target="_blank" rel="noopener">Linux环境下的图形系统和AMD R600显卡编程(11)——R600指令集</a></li><li><a href="https://www.x.org/wiki/Events/XDC2015/Program/turner_glsl_compiler.pdf" target="_blank" rel="noopener">GLSL compiler</a></li><li><a href="https://studiopixl.com/2017-08-27/3d-acceleration-using-virtio.html" target="_blank" rel="noopener">GSoC 2017 - 3D acceleration using VirtIOGPU</a></li><li><a href="https://blog.mecheye.net/2012/06/the-linux-graphics-stack/#rendering-stack" target="_blank" rel="noopener">The Linux Graphics Stack</a></li><li><a href="https://www.phoronix.com/scan.php?page=article&amp;item=glsl_to_tgsi&amp;num=1" target="_blank" rel="noopener">Testing Out Mesa’s GLSL-To-TGSI Translator</a></li><li><a href="https://www.researchgate.net/publication/232626644_Introduction_to_GPU_Programming_with_GLSL" target="_blank" rel="noopener">Introduction to GPU Programming with GLSL</a></li></ul></div><div class="popular-posts-header">相关文章</div><ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><a href="/post/27461.html" rel="bookmark">Zink for OpenGL</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="/post/39ae47e2.html" rel="bookmark">mesa框架与目录结构</a></div></li></ul><div class="post-widgets"><div id="needsharebutton-postbottom"><span class="btn"><i class="fa fa-share-alt" aria-hidden="true"></i></span></div></div><div><div style="text-align:center;color:#ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div><div style="text-align:center;color:#ccc;font-size:16px"><script type="text/javascript" src="https://api.imjad.cn/hitokoto/?cat=&charset=utf-8&length=50&encode=js&fun=sync&source="></script><div id="hitokoto"><script>hitokoto()</script></div></div><div class="reward-container"><div></div> <button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';"> 打赏</button><div id="qr" style="display:none"><div style="display:inline-block"> <img src="/images/alipay.jpg" alt="Winddoing 支付宝"><p>支付宝</p></div></div></div><div><ul class="post-copyright"><li class="post-copyright-author"> <strong>本文作者：</strong> Winddoing</li><li class="post-copyright-link"> <strong>本文链接：</strong> <a href="http://winddoing.github.io/post/58638.html" title="TGSI for Mesa">http://winddoing.github.io/post/58638.html</a></li><li class="post-copyright-statement"> <strong>作者声明：</strong> 本博文为个人笔记, 由于个人能力有限，难免出现错误，欢迎大家批评指正。</li><li class="post-copyright-license"> <strong>版权声明：</strong> 本博客所有文章除特别声明外，均采用<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i> BY-NC-SA</a> 许可协议。转载请注明出处！</li></ul></div><footer class="post-footer"><div class="post-tags"><a href="/tags/mesa/" rel="tag"><i class="fa fa-tag"></i> mesa</a></div><div class="post-nav"><div class="post-nav-item"><a href="/post/793.html" rel="prev" title="GPU page fault"><i class="fa fa-chevron-left"></i> GPU page fault</a></div><div class="post-nav-item"> <a href="/post/62149.html" rel="next" title="rpc">rpc<i class="fa fa-chevron-right"></i></a></div></div></footer></div></article></div></div><div class="comments"><div id="lv-container" data-id="city" data-uid="MTAyMC8yOTM5OC81OTY2"></div></div><script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script></div><div class="toggle sidebar-toggle"><span class="toggle-line toggle-line-first"></span><span class="toggle-line toggle-line-middle"></span><span class="toggle-line toggle-line-last"></span></div><aside class="sidebar"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc"> 文章目录</li><li class="sidebar-nav-overview"> 站点概览</li></ul><div class="post-toc-wrap sidebar-panel"><div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#TGSI中间语言"><span class="nav-number">1.</span> <span class="nav-text">TGSI中间语言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#着色器的编译链接"><span class="nav-number">2.</span> <span class="nav-text">着色器的编译链接</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#GLSL使用"><span class="nav-number">3.</span> <span class="nav-text">GLSL使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#glCompileShader"><span class="nav-number">3.1.</span> <span class="nav-text">glCompileShader</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#virgl中着色器的转换"><span class="nav-number">4.</span> <span class="nav-text">virgl中着色器的转换</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#示例"><span class="nav-number">4.1.</span> <span class="nav-text">示例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#amdgpu中着色器的转换"><span class="nav-number">5.</span> <span class="nav-text">amdgpu中着色器的转换</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#radeonsi-for-shader"><span class="nav-number">5.1.</span> <span class="nav-text">radeonsi for shader</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ISA-Code"><span class="nav-number">5.2.</span> <span class="nav-text">ISA Code</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#着色器形式的转换"><span class="nav-number">5.3.</span> <span class="nav-text">着色器形式的转换</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#示例-1"><span class="nav-number">6.</span> <span class="nav-text">示例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#GLSL着色器"><span class="nav-number">6.1.</span> <span class="nav-text">GLSL着色器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#TGSI-text"><span class="nav-number">6.2.</span> <span class="nav-text">TGSI text</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#TGSI转换GLSL"><span class="nav-number">6.3.</span> <span class="nav-text">TGSI转换GLSL</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其他"><span class="nav-number">6.4.</span> <span class="nav-text">其他</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考"><span class="nav-number">7.</span> <span class="nav-text">参考</span></a></li></ol></div></div><div class="site-overview-wrap sidebar-panel"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"> <img class="site-author-image" itemprop="image" alt="Winddoing" src="/images/Winddoing.jpg"><p class="site-author-name" itemprop="name">Winddoing</p><div class="site-description" itemprop="description">失败缘于忽视细处，成功始于重视小事。</div></div><div class="site-state-wrap motion-element"><nav class="site-state"><div class="site-state-item site-state-posts"> <a href="/archives/"><span class="site-state-item-count">248</span> <span class="site-state-item-name">日志</span></a></div><div class="site-state-item site-state-categories"> <a href="/categories/"><span class="site-state-item-count">57</span> <span class="site-state-item-name">分类</span></a></div><div class="site-state-item site-state-tags"> <a href="/tags/"><span class="site-state-item-count">214</span> <span class="site-state-item-name">标签</span></a></div></nav></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://github.com/Winddoing" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Winddoing" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i> GitHub</a></span><span class="links-of-author-item"><a href="https://gitee.com/winddoing" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;winddoing" rel="noopener" target="_blank"><i class="fa fa-fw fa-codiepie"></i> Gitee</a></span><span class="links-of-author-item"><a href="mailto:winddoing@sina.cn" title="E-Mail → mailto:winddoing@sina.cn" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i> E-Mail</a></span><span class="links-of-author-item"><a href="https://stackoverflow.com/users/9567361/winddoing" title="StackOverflow → https:&#x2F;&#x2F;stackoverflow.com&#x2F;users&#x2F;9567361&#x2F;winddoing" rel="noopener" target="_blank"><i class="fa fa-fw fa-stack-overflow"></i> StackOverflow</a></span><span class="links-of-author-item"><a href="https://travis-ci.org/Winddoing/Winddoing.github.io" title="Travis CI → https:&#x2F;&#x2F;travis-ci.org&#x2F;Winddoing&#x2F;Winddoing.github.io" rel="noopener" target="_blank"><i class="fa fa-fw fa-terminal"></i> Travis CI</a></span></div><div class="cc-license motion-element" itemprop="license"> <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a></div><div class="links-of-blogroll motion-element"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> Links</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"> <a href="https://winddoing.gitbooks.io/embedded_notes/content/" title="https:&#x2F;&#x2F;winddoing.gitbooks.io&#x2F;embedded_notes&#x2F;content&#x2F;" rel="noopener" target="_blank">嵌入式相关</a></li><li class="links-of-blogroll-item"> <a href="http://blog.csdn.net/sdreamq" title="http:&#x2F;&#x2F;blog.csdn.net&#x2F;sdreamq" rel="noopener" target="_blank">CSDN</a></li><li class="links-of-blogroll-item"> <a href="http://www.wowotech.net/" title="http:&#x2F;&#x2F;www.wowotech.net&#x2F;" rel="noopener" target="_blank">蜗窝科技</a></li><li class="links-of-blogroll-item"> <a href="https://blog.csdn.net/xiongxianze" title="https:&#x2F;&#x2F;blog.csdn.net&#x2F;xiongxianze" rel="noopener" target="_blank">xiongxianze</a></li></ul></div><div id="days"></div><script>function show_date_time(){window.setTimeout("show_date_time()",1e3),BirthDay=new Date("02/26/2014 15:00:00"),today=new Date,timeold=today.getTime()-BirthDay.getTime(),sectimeold=timeold/1e3,secondsold=Math.floor(sectimeold),msPerDay=864e5,e_daysold=timeold/msPerDay,daysold=Math.floor(e_daysold),e_hrsold=24*(e_daysold-daysold),hrsold=setzero(Math.floor(e_hrsold)),e_minsold=60*(e_hrsold-hrsold),minsold=setzero(Math.floor(60*(e_hrsold-hrsold))),seconds=setzero(Math.floor(60*(e_minsold-minsold))),document.getElementById("days").innerHTML="已运行"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"}function setzero(e){return e<10&&(e="0"+e),e}show_date_time()</script></div></div></aside><div id="sidebar-dimmer"></div></div></main><footer class="footer"><div class="footer-inner"><div class="copyright"> &copy; 2014 – <span itemprop="copyrightYear">2020</span><span class="with-love" id="heart"><i class="fa fa-heartbeat"></i></span> <span class="author" itemprop="copyrightHolder">Winddoing</span> <span class="post-meta-divider">|</span><span class="post-meta-item-icon"><i class="fa fa-area-chart"></i></span> <span title="站点总字数">652k</span> <span class="post-meta-divider">|</span><span class="post-meta-item-icon"><i class="fa fa-coffee"></i></span> <span title="站点阅读时长">9:53</span></div><div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.9.0</div> <span class="post-meta-divider">|</span><div class="theme-info">主题 – <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> v7.7.0</div><div class="busuanzi-count"><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-item" id="busuanzi_container_site_uv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-user"></i></span><span class="site-uv" title="总访客量"><span id="busuanzi_value_site_uv"></span></span></span> <span class="post-meta-divider">|</span><span class="post-meta-item" id="busuanzi_container_site_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i></span><span class="site-pv" title="总访问量"><span id="busuanzi_value_site_pv"></span></span></span></div><div style="display:inline"><script type="text/javascript">var cnzz_protocol="https:"==document.location.protocol?" https://":" http://";document.write(unescape("%3Cspan id='cnzz_stat_icon_1254703532'%3E%3C/span%3E%3Cscript src='"+cnzz_protocol+"s95.cnzz.com/z_stat.php%3Fid%3D1254703532%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"))</script></div><script>
  function leancloudSelector(url) {
    url = encodeURI(url);
    return document.getElementById(url).querySelector('.leancloud-visitors-count');
  }
  if (CONFIG.page.isPost) {
    function addCount(Counter) {
      var visitors = document.querySelector('.leancloud_visitors');
      var url = decodeURI(visitors.getAttribute('id'));
      var title = visitors.getAttribute('data-flag-title');

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length > 0) {
            var counter = results[0];
            Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
              .then(response => response.json())
              .then(() => {
                leancloudSelector(url).innerText = counter.time + 1;
              })
              .catch(error => {
                console.error('Failed to save visitor count', error);
              })
          } else {
              Counter('post', '/classes/Counter', { title: title, url: url, time: 1 })
                .then(response => response.json())
                .then(() => {
                  leancloudSelector(url).innerText = 1;
                })
                .catch(error => {
                  console.error('Failed to create', error);
                });
          }
        })
        .catch(error => {
          console.error('LeanCloud Counter Error', error);
        });
    }
  } else {
    function showTime(Counter) {
      var visitors = document.querySelectorAll('.leancloud_visitors');
      var entries = [...visitors].map(element => {
        return decodeURI(element.getAttribute('id'));
      });

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url: { '$in': entries } })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length === 0) {
            document.querySelectorAll('.leancloud_visitors .leancloud-visitors-count').forEach(element => {
              element.innerText = 0;
            });
            return;
          }
          for (let item of results) {
            let { url, time } = item;
            leancloudSelector(url).innerText = time;
          }
          for (let url of entries) {
            var element = leancloudSelector(url);
            if (element.innerText == '') {
              element.innerText = 0;
            }
          }
        })
        .catch(error => {
          console.error('LeanCloud Counter Error', error);
        });
    }
  }

  fetch('https://app-router.leancloud.cn/2/route?appId=Q8qpjA3fOO7FEUBqcmcQFptF-gzGzoHsz')
    .then(response => response.json())
    .then(({ api_server }) => {
      var Counter = (method, url, data) => {
        return fetch(`https://${api_server}/1.1${url}`, {
          method: method,
          headers: {
            'X-LC-Id': 'Q8qpjA3fOO7FEUBqcmcQFptF-gzGzoHsz',
            'X-LC-Key': 'tgUTq5bX3fVmn916EMRe65eJ',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(data)
        });
      };
      if (CONFIG.page.isPost) {
        if (CONFIG.hostname !== location.hostname) return;
        addCount(Counter);
      } else if (document.querySelectorAll('.post-title-link').length >= 1) {
        showTime(Counter);
      }
    });
  </script></div></footer></div><script src="/lib/anime.min.js"></script><script src="/lib/velocity/velocity.min.js"></script><script src="/lib/velocity/velocity.ui.min.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script><script>!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script src="/js/local-search.js"></script><script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme: 'forest',
      logLevel: 3,
      flowchart: { curve: 'linear' },
      gantt: { axisFormat: '%m/%d/%Y' },
      sequence: { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script><script src="//cdn.jsdelivr.net/gh/theme-next/theme-next-needmoreshare2@1/needsharebutton.min.js"></script><script>pbOptions={iconStyle:"default",boxForm:"horizontal",position:"bottomCenter",networks:"Weibo,Wechat,QQZone,Twitter,Facebook,Evernote"},new needShareButton("#needsharebutton-postbottom",pbOptions)</script><script>
NexT.utils.loadComments(document.querySelector('#lv-container'), () => {
  window.livereOptions = {
    refer: location.pathname.replace(CONFIG.root, '').replace('index.html', '')
  };
  (function(d, s) {
    var j, e = d.getElementsByTagName(s)[0];
    if (typeof LivereTower === 'function') { return; }
    j = d.createElement(s);
    j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
    j.async = true;
    e.parentNode.insertBefore(j, e);
  })(document, 'script');
});
</script></body></html>